package Page.PaperPage;

import Dao.PaperDao;
import DataClass.Paper;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

import java.net.URL;
import java.sql.SQLException;
import java.sql.Time;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
public class PaperController implements Initializable {
    @FXML
    private TableView<Paper> PaperTable;

    @FXML
    private TableColumn FID;
    @FXML
    private TableColumn FName;
    @FXML
    private TableColumn FContent;
    @FXML
    private TableColumn FAuthor;
    @FXML
    private TableColumn Ftime;


    private PaperModel viewModel;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        viewModel = new PaperModel();

        FID.setCellValueFactory(new PropertyValueFactory<Paper,Integer>("FID"));
        FName.setCellValueFactory(new PropertyValueFactory<Paper,String>("FName"));
        FContent.setCellValueFactory(new PropertyValueFactory<Paper,String>("FContent"));
        FAuthor.setCellValueFactory(new PropertyValueFactory<Paper,String>("FAuthor"));
        Ftime.setCellValueFactory(new PropertyValueFactory<Paper,Integer>("Ftime"));


        PaperTable.setItems(viewModel.dataListProperty());

        try {
            // 从数据库或其他来源获取数据
            viewModel.setDataList(PaperDao.getPaper());
        } catch (SQLException e) {
            viewModel.setDataList(new ArrayList<>());
            System.err.println("Paper 数据获取失败" + e.getMessage());
        }


    }

    public void backButtonClicked(javafx.event.ActionEvent actionEvent) {
        viewModel.backButtonClicked();
    }

}
